package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysSupplierModule;
import com.ruoyi.system.service.ISysSupplierModuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 服务商模块Controller
 * 
 * @author ruoyi
 * @date 2022-06-25
 */
@Api(tags = "服务商模块管理")
@RestController
@RequestMapping("/system/module")
public class SysSupplierModuleController extends BaseController
{
    @Autowired
    private ISysSupplierModuleService sysSupplierModuleService;

    /**
     * 查询服务商模块列表
     */
    @ApiOperation(value = "查询服务商模块列表")
   // @PreAuthorize("@ss.hasPermi('system:module:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSupplierModule sysSupplierModule)
    {
        startPage();
        List<SysSupplierModule> list = sysSupplierModuleService.selectSysSupplierModuleList(sysSupplierModule);
        return getDataTable(list);
    }

    /**
     * 导出服务商模块列表
     */
//    @PreAuthorize("@ss.hasPermi('system:module:export')")
    @Log(title = "服务商模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSupplierModule sysSupplierModule)
    {
        List<SysSupplierModule> list = sysSupplierModuleService.selectSysSupplierModuleList(sysSupplierModule);
        ExcelUtil<SysSupplierModule> util = new ExcelUtil<SysSupplierModule>(SysSupplierModule.class);
        util.exportExcel(response, list, "服务商模块数据");
    }

    /**
     * 获取服务商模块详细信息
     */
    @ApiOperation(value = "获取服务商模块详细信息")
//    @PreAuthorize("@ss.hasPermi('system:module:query')")
    @GetMapping(value = "/{moduleId}")
    public AjaxResult getInfo(@PathVariable("moduleId") Long moduleId)
    {
        return AjaxResult.success(sysSupplierModuleService.selectSysSupplierModuleByModuleId(moduleId));
    }

    /**
     * 新增服务商模块
     */
    @ApiOperation(value = "新增服务商模块")
//    @PreAuthorize("@ss.hasPermi('system:module:add')")
    @Log(title = "服务商模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysSupplierModule sysSupplierModule)
    {

        sysSupplierModule.setCreateBy(getUsername());
        return toAjax(sysSupplierModuleService.insertSysSupplierModule(sysSupplierModule));
    }

    /**
     * 修改服务商模块
     */
    @ApiOperation(value = "修改服务商模块")
  //  @PreAuthorize("@ss.hasPermi('system:module:edit')")
    @Log(title = "服务商模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysSupplierModule sysSupplierModule)
    {
        System.out.println(sysSupplierModule);
        sysSupplierModule.setUpdateBy(getUsername());
        return toAjax(sysSupplierModuleService.updateSysSupplierModule(sysSupplierModule));
    }

    /**
     * 删除服务商模块
     */
    @ApiOperation(value = "删除服务商模块")
//    @PreAuthorize("@ss.hasPermi('system:module:remove')")
    @Log(title = "服务商模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{moduleIds}")
    public AjaxResult remove(@PathVariable Long[] moduleIds)
    {
        return toAjax(sysSupplierModuleService.deleteSysSupplierModuleByModuleIds(moduleIds));
    }
}
